package com.app.stick.factory;/**
 * @program: app-admin
 * @name BusinessFactory
 * @description: 业务操作
 */

import com.app.common.enums.DeleteEnum;
import com.app.common.enums.EnableEnum;
import com.app.common.enums.sick.MonitorTypeEnum;
import com.app.common.utils.bean.BeanUtils;
import com.app.common.utils.spring.SpringUtils;
import com.app.stick.monitor.domain.BizPatientMonitorInfo;
import com.app.stick.monitor.mapper.BizPatientMonitorInfoMapper;
import com.app.stick.notice.domain.BizMessageNotice;
import com.app.stick.notice.mapper.BizMessageNoticeMapper;
import com.app.stick.visit.mapper.BizPatientVisitMapper;
import com.app.websocket.vo.DeviceMonitorVo;
import com.app.websocket.vo.NoticeMessageVo;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;
import java.util.TimerTask;

/**
 *@author:
 *@program: app-admin
 *@name BusinessFactory
 *@description: 业务操作
 */
@Slf4j
public class BusinessFactory {

    /**
     * 记录实时监测数据
     * @param monitorVo
     * @return {@link TimerTask}
     */
    public static TimerTask recordMonitorInfo(DeviceMonitorVo monitorVo) {
        return new TimerTask() {
            @Override
            public void run() {
                if (!MonitorTypeEnum.TYPE_FF.getCode().equals(monitorVo.getMonitorType()) && !MonitorTypeEnum.TYPE_00.getCode().equals(monitorVo.getMonitorType())) {
                    BizPatientMonitorInfoMapper bizPatientMonitorInfoMapper = SpringUtils.getBean(BizPatientMonitorInfoMapper.class);
                    BizPatientMonitorInfo bizPatientMonitorInfo = new BizPatientMonitorInfo();
                    BeanUtils.copyBeanProp(bizPatientMonitorInfo, monitorVo);
                    bizPatientMonitorInfo.setDelFlag(DeleteEnum.NO.getCode());
                    bizPatientMonitorInfo.setCreateTime(new Date());
                    bizPatientMonitorInfoMapper.insert(bizPatientMonitorInfo);
                }
            }
        };
    }

    /**
     * 记录消息通知数据
     *
     * @param noticeMessageVo
     * @return {@link TimerTask}
     */
    public static TimerTask recordNoticeInfo(NoticeMessageVo noticeMessageVo) {
        return new TimerTask() {
            @Override
            public void run() {
                BizMessageNoticeMapper bizMessageNoticeMapper = SpringUtils.getBean(BizMessageNoticeMapper.class);
                BizMessageNotice bizMessageNotice = new BizMessageNotice();
                BeanUtils.copyBeanProp(bizMessageNotice, noticeMessageVo);
                bizMessageNotice.setMsgRead(EnableEnum.YES.getCode());
                bizMessageNotice.setDelFlag(DeleteEnum.NO.getCode());
                bizMessageNotice.setCreateTime(new Date());
                bizMessageNoticeMapper.insert(bizMessageNotice);
            }
        };
    }
}
